<template>
    <div>
        <div class="row heig" :style="{ fontWeight: 700, color: '#000' }">
            <div class="col clt">
                <span :style="{ display: 'inline-block' }">比赛名称 </span>
            </div>
            <div :style="{ width: '80px' }" class="text-center">
                类型
            </div>
            <div :style="{ width: '105px' }">
                比赛时间
            </div>
            <div :style="{ width: '96px' }">
                比赛时长
            </div>
            <div v-show="!isAdmin" :style="{ width: '96px' }">计时方式</div>
        </div>
        <router-link custom v-for="activity in activitys" v-slot="{ navigate }"
            :to="{ name: '比赛详情', params: { ID: activity.ID } }">
            <div @click="navigate" class="row heig cu">
                <div class="col clt">
                    <div :class="jianchatime(activity, datenow).type">{{ jianchatime(activity, datenow).text2 }}</div>
                    <div class="clt-name">{{ activity.name }}</div>
                </div>
                <div :style="{ width: '80px' }" class="text-center">
                    <span>{{ activity.type === "public" ? "公开" : "非公开" }}</span>
                </div>
                <div :style="{ width: '105px' }">
                    <span>
                        {{ TimeYH1(activity.activitystarttime) }}
                    </span>
                </div>
                <div :style="{ width: '96px' }">
                    {{
                        activity.duration ? `${(activity.duration /
                            60).toFixed(1)}小时` : time(activity.activitystarttime, activity.activityendtime)
                    }}
                </div>
                <div v-show="!isAdmin" :style="{ width: '96px' }">{{ activity.duration ? '个人计时' : '统一计时' }}</div>
            </div>
        </router-link>
    </div>
</template>

<script setup lang="ts">
import { jianchatime } from "@/util/jianchatime";
import { TimeYH1 } from "../../util/time";
import Studycodemodel from "../../mysql_interface/studycodemodel";
import { computed } from "vue";
import { Storekey } from "../../interface";
import { useStore } from "vuex";

const p = defineProps<{
    activitys: Studycodemodel.Iactivity[],
    isAdmin?: boolean,
    teamid?: number,
    delactivity?: (activityid?: number) => void,
    checkduplicate?: (activityid?: number) => void,
    paddingLeft?: string
}>()

const store = useStore(Storekey)

const datenow = computed(() => {
    return store.state.time
})
function time(a: Date, b: Date) {
    const t = new Date(b).getTime() - new Date(a).getTime()
    let n: string | number = (t / 60 / 60 / 1000).toFixed(1)
    if (Number(n) === Math.floor(Number(n))) {
        n = Math.floor(Number(n))
    }
    return n + '小时'
}

</script>

<style scoped>
.ztcolor {
    text-decoration: none;
    font-size: 14px;
}

.img {
    background-position: center;
    background-repeat: no-repeat;
    background-size: 100% 100%;
}

.heig {
    height: 48px;
    position: relative;
    line-height: 48px;
    text-decoration: none;
    font-size: 14px;
    cursor: pointer;
    margin-left: 3px;
    overflow: hidden;

}

.heig:hover {
    background-color: var(--color-f5);
    color: var(--color-cheng);
}

.fw-bold {
    color: var(--color-43);
    text-decoration: none;
}

.clt {
    align-items: center;
    position: relative;
    background-position-x: right;
    background-position-y: top;
    background-repeat: no-repeat;
    background-size: 120px 48px;
    overflow: hidden;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    height: 100%;
}


.clt-name {
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    white-space: nowrap;

}

.icon {
    font-size: 24px;
    transform: translateY(3px);
}

.position-absolute {
    width: 400px;
    height: 40px;
    bottom: 10px;
    right: 0px;
    text-align: right;
}

.info {
    background-color: #434343;
    width: 44px;
    height: 24px;
    border-radius: 2px;
    color: #fff;
    display: inline-block;
    text-align: justify;
    font-size: 12px;
    font-weight: 400;
    line-height: 24px;
    text-align: center;
    margin-right: 12px;
}

.primary {
    background: linear-gradient(106.57deg, #00cc2d 0%, #07ca9b 100%);
    width: 44px;
    height: 24px;
    border-radius: 2px;
    color: #fff;
    display: inline-block;
    text-align: justify;
    font-size: 12px;
    font-weight: 400;
    line-height: 24px;
    text-align: center;
    margin-right: 12px;
    transform: translateY(-3px);
}

.danger {
    background: #8c8c8c;
    width: 44px;
    height: 24px;
    border-radius: 2px;
    color: #fff;
    display: inline-block;
    text-align: justify;
    font-size: 12px;
    font-weight: 400;
    line-height: 24px;
    text-align: center;
    margin-right: 12px;
    transform: translateY(-3px);
}

.success {
    background: var(--color-cheng);
    width: 44px;
    height: 24px;
    border-radius: 2px;
    color: #fff;
    display: inline-block;
    text-align: justify;
    font-size: 12px;
    font-weight: 400;
    line-height: 24px;
    text-align: center;
    margin-right: 12px;
    transform: translateY(-3px);
}

.b-info a {
    color: #fff;
    text-decoration: none;
}
</style>